
package com.gp.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.aphidmobile.utils.UI;
import com.gp.R;
import com.gp.data.Pictures;

/**
 * @author shijunxing
 * @className PictureAlbumAdapter
 * @date Jul 22, 2013 3:50:40 PM
 * @version 1.0
 * @Description FlipViewController的适配器
 */
public class PictureAlbumAdapter extends BaseAdapter {

    // 布局压泵
    private LayoutInflater inflater;

    private int repeatCount = 1;

    public PictureAlbumAdapter( Context context ) {
        // 初始化布局压泵
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {

        return Pictures.IMG_DESCRIPTIONS.size() * repeatCount;
    }

    public int getRepeatCount() {
        return repeatCount;
    }

    public void setRepeatCount(int repeatCount) {
        this.repeatCount = repeatCount;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View layout = convertView;
        if (convertView == null) {
            //将布局压进来
            layout = inflater.inflate(R.layout.picturealum, null);
        }
        //准备数据源，这里把数据写在Pictures类里
        final Pictures.Data data = Pictures.IMG_DESCRIPTIONS.get(position
                % Pictures.IMG_DESCRIPTIONS.size());

       //初始化控件，这里用了开源项目里的一个工具类UI
        UI.<ImageView> findViewById(layout, R.id.photo).setImageResource(
                data.id);

        UI.<TextView> findViewById(layout, R.id.description).setText(
                Html.fromHtml(data.description));
        
        UI.<Button> findViewById(layout, R.id.btn_picturealum_back).setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                
            }
        });
       

        return layout;
    }
}
